const express = require(`express`)
const router = express.Router()
var bodyParser = require('body-parser');
var fs=require('fs')
var path=require("path")
var multer = require('multer')		//express框架上传文件所需要的中间件

var upload = multer({			//multer中间件的使用方法可以看官网
  dest: './public/file'
})

router.use(bodyParser.urlencoded({ extended: false }));
router.use((req, res, next) => {
  console.log(`路由执行成功啦~~~`, new Date());
  next()
})


router.post(`/uploadPdf`, upload.single('pic'),(req, res, next) => {
  let file = req.file;
  fs.renameSync(path.join(__dirname,'../public/file/' + file.filename), path.join(__dirname,'../public/file/address_list.'+file.originalname.split('.')[file.originalname.split('.').length-1]))
res.json({
  status: 200,
  msg:"上传成功"
})
})

module.exports = router